package com.chidopi.member.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.chidopi.market.aa.domain.Roles;
import com.chidopi.market.aa.service.IPermissionService;
import com.chidopi.member.dao.IMemberMaintainDao;
import com.chidopi.member.domain.BookCities;
import com.chidopi.member.domain.Member2City;
import com.chidopi.member.domain.Member2Subscribe;
import com.chidopi.member.service.IMemberMaintainService;

public class MemberMaintainServiceImpl implements IMemberMaintainService {
	private static Logger logger = LoggerFactory.getLogger(MemberMaintainServiceImpl.class);
	@Autowired
	@Qualifier("permissionService")
	private IPermissionService permissionService;
	
	@Autowired
	@Qualifier("memberMaintainDao")
	private IMemberMaintainDao memberMaintainDao;
	
	public MemberMaintainServiceImpl() {
		
	}
	
	
	@Override
	public List<Member2City> findMember2City(String username) {
		try {
			List<Roles> list = this.permissionService.getRolesByUsername(username);
			if (list == null || list.size() ==0) return null;
			for (Roles role : list) {
				BookCities bookCity = this.memberMaintainDao.findBookCitiesByRoleId(role.getId());
				if (bookCity != null) {
					return this.memberMaintainDao.findMember2City(bookCity.getId());
				}
			}
		} catch (Exception e) {
			logger.warn("findMember2Subscribe:", e);
		}
		return null;
	}

}
